package structure.stack;

import java.util.Stack;

public class twoStacksQueue {
    private Stack<Integer> pushStack;
    private Stack<Integer> popStack;

    public twoStacksQueue() {
        pushStack = new Stack<>();
        popStack = new Stack<>();
    }

    private void pushToPop(){
        if (popStack.isEmpty()){
            while (!pushStack.isEmpty()){
                popStack.push(pushStack.pop());
            }
        }
    }

    public void add(int n){
        pushStack.push(n);
       // pushToPop();
    }
    public int pull(){
        if (pushStack.isEmpty() && popStack.isEmpty()){
            throw new RuntimeException("Queue 为空");
        }
        pushToPop();
       return popStack.pop();
    }

    public int peek(){
        if (pushStack.isEmpty() && popStack.isEmpty()){
        throw new RuntimeException("Queue 为空");
    }
        pushToPop();
        return popStack.peek();
    }

    public static void main(String[] args) {
        twoStacksQueue twoStacksQueue = new twoStacksQueue();
        twoStacksQueue.add(2);
        twoStacksQueue.add(3);
        System.out.println(twoStacksQueue.pull());
        twoStacksQueue.add(4);
        twoStacksQueue.add(5);
    }


}
